package com.xielaoban.his1.service.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xielaoban.his1.common.ServerResponse;
import com.xielaoban.his1.mappers.FmeditemMapper;
import com.xielaoban.his1.model.Department;
import com.xielaoban.his1.model.Fmeditem;
import com.xielaoban.his1.service.IFmeditemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FmeditemImpl implements IFmeditemService {

    @Autowired
    FmeditemMapper fmeditemMapper;

    @Override
    public ServerResponse qurryByItemCodeOrItemName(String keywords, int pagenum, int pagesize) {
        PageHelper.startPage(pagenum,pagesize);//查看第一页，每页显示10条
        List<Fmeditem> data = fmeditemMapper.qurryByItemCodeOrItemName(keywords);
        PageInfo resultpage = new PageInfo(data);
        return ServerResponse.createBySuccess(resultpage);
    }

    @Override
    public ServerResponse qurryAll(int pagenum,int pagesize) {
        //使用pagehelper分页插件
        PageHelper.startPage(pagenum,pagesize);//查看第一页，每页显示10条
        List<Fmeditem> data = fmeditemMapper.qurryAll();
        //将查询结果封装到pageinfo当中
        PageInfo resultpage = new PageInfo(data);

        return ServerResponse.createBySuccess(resultpage);
    }

    @Override
    public ServerResponse qurryOneById(int id) {
        Fmeditem data = fmeditemMapper.qurryOneById(id);
        return ServerResponse.createBySuccess(data);
    }

    @Override
    public ServerResponse insertOne(Fmeditem fmeditem) {
        fmeditem.setCreationDate(new Date(System.currentTimeMillis()));
        int result = fmeditemMapper.insertOne(fmeditem);
        return ServerResponse.createBySuccess(result);
    }

    @Override
    public ServerResponse deleteOneById(int Id) {
        int result = fmeditemMapper.deleteOneById(Id);
        return ServerResponse.createBySuccess(result);
    }

    @Override
    public ServerResponse exPortAllData() {
        return null;
    }

    @Override
    public ServerResponse updateOne(Fmeditem fmeditem) {
        fmeditem.setCreationDate(new Date(System.currentTimeMillis()));
        int result = fmeditemMapper.updateOne(fmeditem);
        return ServerResponse.createBySuccess(result);
    }
}
